#ifndef COLOR_UTILS_H_
#define COLOR_UTILS_H_

class AdjacentMatrix;
class CacheFriendlyAdjacentMatrix;

class Colors {
    friend void reorg(CacheFriendlyAdjacentMatrix &graph, Colors &color);
    friend void unreorg(CacheFriendlyAdjacentMatrix &graph, Colors &color);
    friend void buildColorLabel(CacheFriendlyAdjacentMatrix &graph, Colors &color);
    friend void unBuildColorLabel(CacheFriendlyAdjacentMatrix &graph, Colors &color);
public:
    int n, threadNum;

private:
    int *colors, *nodeNumberCount, *label, *unlabel;

    inline void releaseNodeNumberCount();

    inline void release();

    inline void releaseAndAllocate();

public:
    Colors();

    void dumpToObjectFile(const char * const fileName) const;

    const int * getColors() const;

    const int * getlabel() const;

    const int * getunlabel() const;

    const int * getNodeNumberCount() const;

    void print() const;

    void printSummary() const;

    ~Colors();

    void readFromObjectFile(AdjacentMatrix &adjMatrix, const char * const fileName);

    void color_BFS_DeltaDepth(AdjacentMatrix &adjMatrix, int source, int deltaDepth);

    void refine(int threadNum);
};

void reorg(CacheFriendlyAdjacentMatrix &graph, Colors &color);
void unreorg(CacheFriendlyAdjacentMatrix &graph, Colors &color);
void reorgResult(CacheFriendlyAdjacentMatrix &graph);

#endif
